<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Site extends CI_Controller {
    
	function Site()
	{
		parent::__construct();

		// $this->load->helper(array('form', 'url'));
		$this->load->library('form_validation');
		$this->form_validation->set_error_delimiters('<div class="help-inline">', '</div>');
	}
        
	public function index()
	{
            $this->load->model('navigation');
            $articles = $this->navigation->get_last_ten_entries();
           // $this->load->view('admin',$articles);
            $this->smarty->assign('articles',json_decode(json_encode($articles),true));
            $this->smarty->view('site.tpl');
	}
        
	public function new_entry()
	{
            $data = array();
            $this->load->model('navigation');
           // $this->load->view('admin',$articles);
            $this->smarty->assign('section','new_entry');
            $this->smarty->assign('insertURL',base_url('admin/new_entry'));
            
            // Set the validation rules if this is a submit
            if ( $this->input->post('action') == 'submit' )
            {
                    $this->form_validation->set_rules('navigation_name', 'Identificator', 'trim|required|min_length[2]|max_length[32]|xss_clean');
                    $this->form_validation->set_rules('title', 'Title', 'trim|required|min_length[2]|max_length[100]|xss_clean');
                   /* $this->form_validation->set_rules('password', 'Password', 'trim|required|matches[passconf]|md5');
                    $this->form_validation->set_rules('passconf', 'Password Confirmation', 'trim|required');
                    $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
                    $this->form_validation->set_rules('state', 'State', '');*/

                    if ( ! $this->form_validation->run() )
                    {
                            $data['error'] = 'Check and fix the form errors below';
                    }
                    else
                    {
                        $this->insert_entry();
                        $data['message'] = 'Thanks for posting!';
                    }
            }
            $data['base_url'] = base_url();
            $this->smarty->view('site.tpl',$data);
	}
}
